package com.fundcrawler.scheduler;

import com.fundcrawler.service.DataService;
import com.fundcrawler.service.FundCrawlerAspxService;
import com.fundcrawler.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/*
    004744  易方达创业板ETF连接C
    020137  平安医疗健康混合C
    019764	中欧半导体产业股票C
    015968	永赢半导体产业智选混合C
    024038	银华恒生港股通中国科技ETF连接C
    004320	前海开源沪港深乐享生活灵活配置
    018994	中欧数字经济混合C
    014777	富国中证芯片产业ETF连接C
    002974	广发信息技术ETF连接C
    018125	永赢先进制造智选混合C
    004815	中欧红利优享灵活配置混合C
    021031	汇添富国证港股通创新药ETF连接C
    015187	汇添富消费升级混合C
* */
@Component
public class FundUpdateTask {

    private final FundCrawlerAspxService crawler;
    private final NotificationService notify;

    public FundUpdateTask(FundCrawlerAspxService crawler, NotificationService notify) {
        this.crawler = crawler;
        this.notify = notify;
    }

    @Autowired
    private DataService dataService;

    @Scheduled(cron = "0 0 19 * * ?") // 每天 19:00
    public void updateAllFunds() {
        try {
            dataService.updateAllFunds();
            notify.pushWechat("基金更新完成", "✅ 所有基金已更新至最新净值");
        } catch (Exception e) {
            String msg = "❌ 基金更新失败: " + e.getMessage();
            notify.sendErrorAlert("基金更新失败", msg);
            notify.pushWechat("系统异常", msg);
        }
    }

}
